fn main() {
    println!("-----------------");
    test01_create_enum();
    println!("-----------------");
    test02_func();
    println!("-----------------");
    test03_struct();
    println!("-----------------");
    test04_enum_data();
    println!("-----------------");
    test05_enum_diff_data();
    println!("-----------------");
    test06_enum_inner_type();
    println!("-----------------");
    test07_option();
    println!("-----------------");
}
fn test07_option() {
    let some_number = Some(5);
    let some_char = Some('e');
    let absent_number: Option<i32> = None;

    let x: i8 = 5;
    let y: Option<i8> = Some(5);

    //let x = x + y;//err
    let x = x + y.unwrap();

    println!("x={x}");
}

#[derive(Debug)]
enum Message {
    Quit,
    Move { x: i32, y: i32 },
    Write(String),
    ChangeColor(i32, i32, i32),
}
impl Message {
    fn call(&self) {
        println!("{self:#?}");
    }
}
fn test06_enum_inner_type() {
    let message = Message::Move { x: 1, y: 2 };

    println!("{message:#?}");
    message.call();
}

#[derive(Debug)]
enum IpAddrAlter {
    V4(u8, u8, u8, u8),
    V6(String),
}
fn test05_enum_diff_data() {
    let home = IpAddrAlter::V4(127, 0, 0, 1);
    let loopback = IpAddrAlter::V6(String::from("::1"));

    println!("{home:#?}");
    println!("{loopback:#?}");
}

#[derive(Debug)]
enum IpAddr {
    V4(String),
    V6(String),
}

fn test04_enum_data() {
    let home = IpAddr::V4(String::from("127.0.0.1"));
    println!("{home:#?}");
}

#[derive(Debug)]
struct Ip {
    kind: IpAddrKind,
    ip: String,
}

fn test03_struct() {
    let home = Ip {
        kind: IpAddrKind::V4,
        ip: String::from("127.0.0.1"),
    };
    println!("{home:#?}");
}

fn route(ip_kind: IpAddrKind) {
    println!("{ip_kind:#?}");
}

fn test02_func() {
    let four = IpAddrKind::V4;
    route(four);
}

fn test01_create_enum() {
    let four = IpAddrKind::V4;
    let six = IpAddrKind::V6;
    println!("{four:#?}");
    println!("{six:#?}");
}

#[derive(Debug)]
enum IpAddrKind {
    V4,
    V6,
}
